package com.wh1200.mybatis.xmlless.resolver

import com.wh1200.mybatis.xmlless.config.BaseResolverTest
import com.wh1200.xmlless.test.dao.StudentDAO
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class SqlConditionExpressionResolverTest : BaseResolverTest(StudentDAO::class.java) {

  @Test
  fun parseExpression() {
    val str = "TRUNCATE(sum(t1.count)/sum(t1.price), 0)"
    val exp = ExpressionResolver.parseExpression(str)
    assertEquals(str, exp.toSql())
    val s2 = "date_format(t1.name, '%Y-%m-%d')"
    assertEquals(s2, ExpressionResolver.parseExpression(s2).toSql())
  }

  @Test
  fun includeSpecificString() {
    val str = "date_format(date, '%Y-%m-%d') = date_format(date, '%Y-%m-%d')"
    val exp = ExpressionResolver.parseExpression(str)
    exp.getNodes().forEach {
      println(it.toSql())
    }
    println(ExpressionResolver.parseExpression("distinct abc").getNodes())
    println(ExpressionResolver.parseExpression("distinctAbc").getNodes())
    println(ExpressionResolver.parseExpression("distinct(abc)").getNodes())
    println(ColumnsResolver.FUNCTION_PATTERN.matches("min(abc)"))
    println(ColumnsResolver.FUNCTION_PATTERN.matches("distinct(abc)"))
    ColumnsResolver.FUNCTION_PATTERN.find("distinct(abc)")?.let {
      it.groups.forEach {
        println(it?.value)
      }
    }
  }



}

